翻訳と辞書
Words near each other
・ Rules Reservoir
・ Rules!
・ Ruleta
・ Ruleta (song)
・ Ruleta de la Muerte (1998)
・ Ruleta de la Muerte (1999)
・ Ruleta de la Muerte (2012)
・ Ruleta de la Muerte (2015)
・ Ruletero a toda marcha
・ Rule of thirds
・ Rule of thirds (disambiguation)
・ Rule of thirds (diving)
・ Rule of thirds (military)
・ Rule of three
・ Rule of three (aeronautics)
Rule of three (C++ programming)
・ Rule of three (computer programming)
・ Rule of three (economics)
・ Rule of three (statistics)
・ Rule of Three (Wicca)
・ Rule of three (writing)
・ Rule of thumb
・ Rule of tincture
・ Rule of twelfths
・ Rule of Wen and Jing
・ RULE Project
・ Rule Supreme
・ Rule the School
・ Rule the World
・ Rule utilitarianism


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Rule of three (C++ programming) : ウィキペディア英語版
Rule of three (C++ programming)
The rule of three, rule of five, and rule of 0 are rules of thumb in C++ for the building of exception-safe code and for formalizing rules on resource management. It accomplishes this by prescribing how the default members of a class should be used to accomplish this task in a systematic manner.
== Rule of Three ==
The rule of three (also known as the Law of The Big Three or The Big Three) is a rule of thumb in C++ (prior to C++11) that claims that if a class defines one (or more) of the following it should probably explicitly define all three:
* destructor
* copy constructor
* copy assignment operator
These three functions are special member functions. If one of these functions is used without first being declared by the programmer it will be implicitly implemented by the compiler with the default semantics of performing the said operation on all the members of the class. The default semantics are:
* Destructor – Call the destructors of all the object's class-type members
* Copy constructor – Construct all the object's members from the corresponding members of the copy constructor's argument, calling the copy constructors of the object's class-type members, and doing a plain assignment of all non-class type (e.g., ''int'' or pointer) data members
* Copy assignment operator – Assign all the object's members from the corresponding members of the assignment operator's argument, calling the copy assignment operators of the object's class-type members, and doing a plain assignment of all non-class type (e.g. ''int'' or pointer) data members.
The Rule of Three claims that if one of these had to be defined by the programmer, it means that the compiler-generated version does not fit the needs of the class in one case and it will probably not fit in the other cases either. The term "Rule of three" was coined by Marshall Cline in 1991.
An amendment to this rule is that if Resource Acquisition Is Initialization (RAII) is used for the class members, the destructor may be left undefined (also known as The Law of The Big Two).
Because implicitly-generated constructors and assignment operators simply copy all class data members, one should define explicit copy constructors and copy assignment operators for classes that encapsulate complex data structures or have external references such as pointers, since only the pointer gets copied, not the object it points to. In the case that this default behavior is actually the intended behavior, an explicit declaration can prevent ambiguity.

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Rule of three (C++ programming)」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.